#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static bool palindrone(const vector<int>& v) {
    for (int i = 0, j = v.size() - 1; i < j; ++i, --j) {
        if (v[i] != v[j])
            return false;
    }
    return true;
}

static vector<int> vector_add(const vector<int>& a, const vector<int>& b) {
    vector<int> r;
    int c = 0;
    int i = 0;
    while (i < a.size() && i < b.size()) {
        c += a[i] + b[i];
        r.push_back(c % 10);
        c /= 10;
        ++i;
    }
    while (i < a.size()) {
        c += a[i];
        r.push_back(c % 10);
        c /= 10;
        ++i;
    }
    while (i < b.size()) {
        c += b[i];
        r.push_back(c % 10);
        c /= 10;
        ++i;
    }
    if (c) 
        r.push_back(c);
    return r;
}

static vector<int> vector_init(int num) {
    vector<int> r;
    while (num) {
        r.push_back(num % 10);
        num /= 10;
    }
    return r;
}

int main() {
    int r = 0;
    for (int i = 0; i < 10000; ++i) {
        vector<int> v = vector_init(i);
        for (int j = 0; j < 50; ++j) {  
            vector<int> p = v;
            reverse(p.begin(), p.end());
            v = vector_add(v, p);
            if (palindrone(v)) {
                ++r;
                break;
            } else if (j == 49) {
                // cout << i << ' ' << v.size() << endl;
            }
        }
    }
    cout << 10000 - r << endl;
}
